<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Document</title>
</head>

<body>
  <h1>Test Fun In Page</h1>
  <hr />
  <h2>window utools object function!!</h2>
  <hr />
  <script type="module">
    import * as utools from "../lib/es/index.js"
    Object.assign(window, utools)
    console.log(utools)
    // console.log(utools.isObject({}))
    // console.log(utools.isPlainObject({}))
    // console.log(utools.isPrimitive(123))
    // console.log(utools.isPrimitive(null))
    // console.log(utools.isPrimitive({}))    
    // 设置一个监听器
    const cleanup = monitorStorage({
      type: 'both',
      onError: (error) => {
        // 自定义错误处理
        console.error('Storage error:', error);
      }
    });
    
    // 监听事件
    window.addEventListener('local', (e) => {
      const event = e;
      console.log('Storage changed:', {
        key: event.key,
        newValue: event.newValue,
        oldValue: event.oldValue,
        storageArea: event.storageArea
      });
    });

    setLocalStorage('name', 'zhangsan')

    // 页面关闭时清理监听器
    window.addEventListener('unload', cleanup);

  </script>
  <script>
    let uapdatevalue = function () {
      setLocalStorage('name', 'lisi-')
    }
  </script>
  <button onclick="uapdatevalue()">clike</button>
</body>

</html>